package com.zhihuichongcheng.application.ui.approval.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.smartlib.cmnObject.recycleView.OnItemOnclick;
import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.bean.approval.ApprovalWaitBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 3water on 2016/11/10.
 */

public class SendTomeApprovalAdapter extends RecyclerView.Adapter<SendTomeApprovalAdapter.ViewHold> {

    private OnItemOnclick<ApprovalWaitBean> onItemOnclick;
    private Context mContext;
    private List<ApprovalWaitBean> mListData = new ArrayList<>();

    public SendTomeApprovalAdapter(Context context)
    {
        this.mContext = context;
    }
    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_my_approval,null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, final int position) {
       final ApprovalWaitBean bean = mListData.get(position);
//        holder.mTvName.setText(bean.getName());
//        holder.mTvTitle.setText(bean.getTitle());
//        holder.mTvTime.setText(bean.getTime());
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onItemOnclick!=null)
                {
                    onItemOnclick.onClick(bean,position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    public void setOnItemOnclick(OnItemOnclick<ApprovalWaitBean> onItemOnclick) {
        this.onItemOnclick = onItemOnclick;
    }

    public void setdata(List<ApprovalWaitBean> list) {
        this.mListData.addAll(list);
    }

    class ViewHold extends RecyclerView.ViewHolder{
        private TextView mTvTitle,mTvName,mTvTime;
        private View view;

        public ViewHold(View itemView) {
            super(itemView);
            view = itemView;
            mTvTitle = (TextView)itemView.findViewById(R.id.tv_title);
            mTvName = (TextView)itemView.findViewById(R.id.tv_name);
            mTvTime = (TextView)itemView.findViewById(R.id.tv_time);
        }
    }
}
